<?php

namespace App\Admin\Controllers;

use App\Models\Cashier;
use App\Models\RecordRecharge;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class RecordRechargeController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '充值记录';
    protected $type = [1 => '开通会员', 2 => '会员充值', 3 => '充值赠送'];
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new RecordRecharge());

        //$grid->column('store_id', __('Store id'));
        $grid->column('member.name', '会员名称');
        $grid->column('price', '金额');
        $grid->column('type', __('Type'))
            ->using($this->type);
        $grid->column('cashier.name', __('Cashier id'));
        $grid->column('created_at', __('Created at'));

        $grid->disableCreateButton();
        $grid->actions(function($actions) {
            $actions->disableView();
        });
        $grid->filter(function($filter) {
            $filter->disableIdFilter();
            $filter->equal('member.name', '名称');
            $filter->equal('cashier_id', '收银员')
                ->select(Cashier::all()->pluck('name', 'id'));
        });

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(RecordRecharge::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('store_id', __('Store id'));
        $show->field('member_id', __('Member id'));
        $show->field('price', '金额');
        $show->field('type', __('Type'));
        $show->field('cashier_id', __('Cashier id'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));
        $show->field('deleted_at', __('Deleted at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new RecordRecharge());

        //$form->number('store_id', __('Store id'));
        $form->text('member.name', __('会员名称'))->disable();
        $form->text('price', '金额')->disable();
        $form->select('type', __('Type'))->options($this->type)->default(1)->disable();
        $form->text('cashier.name', __('Cashier id'))->disable();

        return $form;
    }
}
